<?php
/**
 * app 大话水浒
 * @author will
 */
class app_Overlord_Colosseum {
	/**
	 * Transcript添加操作
	 * @param unknown_type $key
	 * @param unknown_type $value
	 */
	public static function addTranscript($table , $key , $value){
		$time = time(); //获取时间
		
		$Db = loadDB('app_transcript');
		$value = serialize($value);
		//把数据写入数组
		$insert_date = array(
			'Key' => $key,
			'Value' => $value,
			'time' => $time,
		);
		$success = $Db->doInsert($table , $insert_date);
		return $success ? 0 : 951;
	}
	/**
	 * Transcript查询全部操作
	 */
	public static function allTranscript($table){
		
		$Db = loadDB('app_transcript');
		
		$result = $Db->getall("SELECT * FROM {$table}");
		
		if(empty($result)) return array();
		if (!empty($result)){
			foreach($result as $k => $row) {
				$result[$k]['Value'] = unserialize($row['Value']);
			}
		}
		return $result;
	}
	/**
	 * Transcript查询单个表
	 */
	public static function oneTranscript($table , $key){
		$Db = loadDB('app_transcript');
		$result = $Db->getOne("SELECT * FROM {$table} WHERE `Key` = '{$key}'");
	
		if(empty($result)) return array();
		$result['Value'] = unserialize($result['Value']);
		
		return $result;
	}
	/**
	 * Transcript修改表内容
	 * @param unknown_type $key
	 */
	public static function alterTranscript($table , $key , $value){
		$time = time(); //获取时间
		$Db=loadDB('app_transcript');
		
		$value = serialize($value);
		$update_data = array(
			'Value' => $value,
			'time' => $time,
		);
	
		$success = $Db->doUpdate($table , $update_data , "`Key` = '{$key}'");
		
		return $success ? 0 : 952;
	}
	/**
	 * Transcript批量查询
	 * Enter description here ...
	 * @param unknown_type $table
	 * @param unknown_type $key
	 */
	public static function inTranscript($table , $keys){
		
		if(empty($keys)) return array();
		
		$key_arr = array();
		foreach($keys as $key) {
			$key_arr[] = "'{$key}'";
		}
	
		$key_str = implode($key_arr , ',');
		$Db = loadDB('app_transcript');
		$result = $Db->getAll("SELECT * FROM {$table} WHERE `Key` IN ($key_str)");
		if(empty($result)) return array();
		foreach($result as $k => $row) {
			$result[$k]['Value'] = unserialize($row['Value']);
		}
		return $result;
	}
}
# end of script